package com.banmao.dynamicDS.config;


import com.banmao.dynamicDS.datasource.DatasourceContextHolder;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

import java.util.Map;

public class DynamicDataSource extends AbstractRoutingDataSource {

    public DynamicDataSource(Map<Object, Object> targetDatasources, Object defaultDatasource) {
        super.setTargetDataSources(targetDatasources);
        super.setDefaultTargetDataSource(defaultDatasource);
        super.afterPropertiesSet();
    }

    @Override
    protected Object determineCurrentLookupKey() {
        return DatasourceContextHolder.getDS();
    }

}
